package com.ct.gd.passport.domain;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import com.ct.gd.passport.common.connect.CtServer;
import com.ct.gd.passport.common.constants.Config;
import com.ct.gd.passport.common.constants.Protocol;
import com.fuckhtc.gson.Gson;
import com.fuckhtc.gson.annotations.SerializedName;
import com.fuckhtc.gson.reflect.TypeToken;
import com.up91.common.android.connect.Params;
import com.up91.common.android.exception.NullDataException;

public class ExhibitionInfo {
	// 普通优惠信息
	public static int	DISCOUNT_TYPE_SIMPLE	= 1;
	// 特别优惠信息
	public static int	DISCOUNT_TYPE_VIP		= 2;

	@SerializedName("id")
	private int			id;

	@SerializedName("name")
	private String		name;
	
	@SerializedName("duration")
	private String duration;
	
	private String district;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDuration() {
		return duration;
	}

	public void setDuration(String duration) {
		this.duration = duration;
	}

	public static List<ExhibitionInfo> load() {
		Params params = new Params();
		params.put(Protocol.Fields.PAGE_INDEX, Config.DEFAULT_PAGE_INDEX);
		params.put(Protocol.Fields.PAGE_SIZE, Config.DEFAULT_PAGE_SIZE);
		params.put(Protocol.Fields.DISCOUNT_DISTRICT, Config.currentArea.code);
//		params.put(Protocol.Fields.DISCOUNT_TYPE, type);
//		params.put(Protocol.Fields.DISCOUNT_TYPE, DISCOUNT_TYPE_SIMPLE);

		if (Config.ON_LINE) {
			String json = CtServer.getServer().doGet(Protocol.Commands.EXHIBITION_QUERY, params);
//			TypeToken<List<DiscountInfo>> typeToken = new TypeToken<List<DiscountInfo>>() {
//			};
//			return new Gson().fromJson(json, typeToken.getType());
			try {
				JSONObject jObj = new JSONObject(json);
				
				TypeToken<List<ExhibitionInfo>> typeToken = new TypeToken<List<ExhibitionInfo>>() {
				};
				return new Gson().fromJson(jObj.getString(Protocol.Fields.DATA), typeToken.getType());
			} catch (JSONException e) {
				e.printStackTrace();
				throw new NullDataException();
			}
		}

		List<ExhibitionInfo> infos = new ArrayList<ExhibitionInfo>();
		ExhibitionInfo info = null;
		for (int i = 0; i < 20; i++) {
			info = new ExhibitionInfo();
			info.setId(i);
			info.setName("中环第" + i + "个优惠信息");
			infos.add(info);
		}
		return infos;
	}

}
